/-boot ...
BootController.ts
BootLayout.ts
StorageLoader.ts
boot.ts
/-docs
/-editor
/-files
/-files-old
/-imports
/-layout
MainLayout.ts
file.html
folder.html
page.html
teapo.css
/-storage
/-tests
/-typings
Dom.ts
TypeScriptService.ts
functions.ts
ko.ts
nteapo.html
persistence.api.ts
persistence.ts
shell.ts
teapo.html
teapo.ts
try.html
try.js
x
      var loadingFromPersistence = this._persistence && this._persistence.editedUTC > this._domStorage.editedUTC;
1
module teapo.boot {
2
3
  export class StorageLoader {
4
5
    private _domStorage: storage.attached.dom.LoadStorage;
6
7
    private _callbacks: StorageLoader.Callbacks = null;
8
9
    private _indexedDBDetectCompleted = false;
10
    private _webSqlDetectCompleted = false;
11
    private _persistenceName: string = null;
12
    private _persistence: storage.attached.LoadStorage = null;
13
14
    constructor(
15
      private _dom: Dom,
16
      private _storageElement: HTMLElement,
17
      private _uniqueKey: string) {
18
    }
19
20
    loadStorage(callbacks: StorageLoader.Callbacks) {
21
      if (this._callbacks)
22
        throw new Error('Cannot load storage twice.');
23
24
      this._callbacks = callbacks;
25
26
      try {
27
        this._domStorage =
28
        new storage.attached.dom.DetectStorage(this._storageElement, this._dom.documenOverride).
29
          detectStorageSync();
30
      }
31
      catch (err) {
32
        this._callbacks.detectionComplete(err, null, null, null);
33
        return;
34
      }
35
36
      var detectIndexedDB = new storage.attached.indexedDB.DetectStorage();
37
      var detectWebSQL = new storage.attached.webSQL.DetectStorage();
38
39
      detectIndexedDB.detectStorageAsync(this._uniqueKey, (error, load) => {
40
        this._indexedDBDetectCompleted = true;
41
42
        if (error) {
43
          if (!this._webSqlDetectCompleted)
44
            return; // wait for webSQL, it can still succeed
45
46
          // revert to webSQL results
47
          this._detectCompleted();
48
        }
49
        else {
50
          this._persistence = load;
51
          this._persistenceName = 'indexedDB';
52
53
          this._detectCompleted();
54
        }
55
      });
56
57
      detectWebSQL.detectStorageAsync(this._uniqueKey, (error, load) => {
58
        this._webSqlDetectCompleted = true;
59
60
        if (this._persistence)
61
          return;
62
63
        this._persistence = load;
64
        if (this._indexedDBDetectCompleted)
65
          this._detectCompleted();
66
      });
67
    }
68
69
    private _detectCompleted() {
70
      var loadingFromPersistence = this._persistence && this._persistence.editedUTC > this._domStorage.editedUTC;
71
72
      var sourceLoad = loadingFromPersistence ? this._persistence : this._domStorage;
73
      var targetLoad = loadingFromPersistence ? this._domStorage : this._persistence;
74
75
      this._callbacks.detectionComplete(
76
        null,
77
        this._persistenceName,
78
        sourceLoad.editedUTC,
79
        loadingFromPersistence);
80
81
      var byFullPath: { [fullPath: string]: { [property: string]: string; }; } = {};
82
      var totalFileCount = 0;
83
      var loadedFileCount = 0;
84
      sourceLoad.load({
85
        files: (fileCount) => {
86
          totalFileCount = fileCount;
73:0